package 笔试;

import java.util.Scanner;

public class 裁缝2 {
    public static int resault = 0;
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int bigLen = scan.nextInt();
        int m = scan.nextInt();
        String bigStr = scan.next();
        int[] smalLen = new int[m];
        int sum = 0;
        for (int i = 0; i < m; i++) {
            smalLen[i] = scan.nextInt();
            sum += smalLen[i];
        }
        if(sum != bigLen) {
            System.out.println(0);
            System.exit(0);
        }
        String[] strings = new String[m];
        for (int i = 0; i < m; i++) {
            strings[i] = scan.next();
        }

        function(strings, bigStr, 0);
        System.out.println(resault);
    }

    public static void function(String[] strings, String bigStr, int i ) {
        if(i == strings.length) {
            StringBuilder sb = new StringBuilder();
            for (String s : strings) {
                sb.append(s);
            }
            if(bigStr.equals(sb.toString())) {
                resault++;
            }
        } else {
            for (int k = i; k < strings.length; k++) {
                if(isSwap(strings, i, k)) {
                    swap(strings, i, k);
                    function(strings, bigStr, i+1);
                    swap(strings, i, k);
                }
            }
        }
    }

    public static void swap(String[] strings, int i, int j) {
        String tmp = strings[i];
        strings[i] = strings[j];
        strings[j] = tmp;
    }

    public static boolean isSwap(String[] strings, int i, int j) {
        for (int k = i; k < j; k++) {
            if(strings[k].equals(strings[j])) {
                return false;
            }
        }
        return true;
    }
}
